<?php

 $debugArr = array();
 $debug = true;

function pr($data=array(),$line='',$file='')
{
 global $debug;
 global $debugArr;
 if($debug==false)return false;
 $pr = "$file on Line $line<br>";
 $pr .= '<pre style="border-radius:10px;padding:10px;color:#fff;background-color:#000;font-size:20px;">';
 $pr .= print_r($data,true);
 $pr .= '</pre>';

// echo $pr;exit;
 array_push($debugArr,$pr);
 }

function pq($data='',$line='',$file='')
{
    global $debugArr;
     global $debug;
 if($debug==false)return false;
  $pr = "$file on Line $line<br>";
  $pr .='<div style="width:700px;border-radius:10px;
  padding:10px;color:green;background-color:yellow;font-size:20px;">';
  $pr .= print_r($data,1);
  $pr .= '</div>';
 array_push($debugArr,$pr);
}

function pr1($data=array())
{
  global $debugArr;
   global $debug;
 if($debug==false)return false;
  $pr = '<div style="width:700px;border-radius:10px;
  padding:10px;color:red;background-color:yellow;font-size:20px;">';
  $pr .= print_r($data,1);
  $pr .= '</div>';
 array_push($debugArr,$pr);
}

/*
 * Used to upload files
 * @param $files ARRAY ( a.k.a $_FILES )
 * @param $destDir STRING (dir path where you want to upload)
 * @return ARRAY with msg, flag, fileName
 *
 * NOte :
 * 1. filename will dynamically  unique as date('ymdHis').'_'.uniqid()
 * 2. Detect dynamically fileIndex as "var $uploadIndex"
 */
function upload($files=array() , $destDir = 'uploads')
{
  $flag = false;
  $msg = '';
  $fileName = '';

  if(empty($files)) {
      return array('msg'=>'Array empty', 'flag'=>false);
  }

  $uploadKeys = array_keys($files);
  $uploadIndex =$uploadKeys[0];

  if(isset($files[$uploadIndex]) && !empty($files[$uploadIndex]))
  {
    if($files[$uploadIndex]['error']==0) {
      if(is_uploaded_file ($files[$uploadIndex]['tmp_name'])){
        $fileName = $files[$uploadIndex]['name'];
        $fileName = date('ymdHis').'_'.uniqid().$fileName;
        $source = $files[$uploadIndex]['tmp_name'];
        $dest = "{$destDir}/{$fileName}";
        $tmp =  move_uploaded_file($source, $dest);
        if($tmp == true){
          $msg =  "WOW !! Success !!!!";
          $flag = true;

        } else {
          $msg = "Your Bad !! May be upload dir didn't exists..";
          $flag = false;
        }
      }
    } else
    if($files[$uploadIndex]['error']==1) {
      $msg = "File Size exceed 2MB";
      $flag = false;
    } else if($files[$uploadIndex]['error']==4) {
      $msg = "Please upload file";
      $flag = false;
    }
  }//if(isset($_FILES[$uploadIndex]) && !empty($_FILES[$uploadIndex]))

  return array('msg'=>$msg,
               'flag'=>$flag,
               'fileName'=>$fileName);
}// end upload


function getCountries()
{
  return array('1'=>'India',
      '2'=>'Pakistan',
      '3'=>'Nepal',
      '4'=>'Bhutan',
      '5'=>'SriLanka',
      '6'=>'China',
      '7'=>'BanglaDesh');
}


function success($msg="")
{
  return '<div class="alert alert-success">'.$msg.'</div>';
}


function getStatus($status=0)
{
  if($status==0){
    return '<span class="glyphicon glyphicon-star-empty"></span>';
  } else {
    return '<span class="glyphicon glyphicon-star"></span>';
  }
}

function toggleStatus($status=0)
{
  return $status==0 ? 1 : 0 ;
}
function getGender($gender='')
{
  return $gender=='m'?'male':'female';
}

